package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.FlightDestination;
import cn.wolfcode.luowowo.article.domain.FlightMessage;
import cn.wolfcode.luowowo.article.mapper.FlightDestinationMapper;
import cn.wolfcode.luowowo.article.mapper.FlightMessageMapper;
import cn.wolfcode.luowowo.article.service.IFlightDestinationService;
import cn.wolfcode.luowowo.common.exception.LogicException;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

@Service
public class FlightDestinationSerivceImpl implements IFlightDestinationService {
    @Autowired
    private FlightDestinationMapper flightDestinationMapper;
    @Autowired
    private FlightMessageMapper flightMessageMapper;

    public List<FlightDestination> getDestByinitials(String initials) {
        List<FlightDestination> list = new ArrayList<>();
        String[] split = initials.split(",");
        for (String initial : split) {
            List<FlightDestination> flightDestinations = flightDestinationMapper.queryDestByInitial(initial);
            if (flightDestinations.size() > 0) {
                for (FlightDestination flightDestination : flightDestinations) {
                    list.add(flightDestination);
                }
            }
        }
        return list;
    }

    public List<Map<String, Object>> getDestByinitials2(String initials) {
        List<Map<String, Object>> data = new ArrayList<>();
        String[] split = initials.split(",");//截取A到E的首字母,数组存放
        for (String initial : split) {
            List<FlightDestination> flightDestinations = flightDestinationMapper.queryDestByInitial(initial);
            Map<String, Object> map = new HashMap<>();
            map.put("initial", initial);//通过对象拿到首字母
            map.put("fdests", flightDestinations);
            data.add(map);
        }
        return data;
    }

    public List<FlightDestination> getDestByIsHot() {
        return flightDestinationMapper.queryDestByIsHot();
    }

    public List<FlightMessage> getFlightMessage(String orgCity, String dstCity, Date time) throws LogicException{
        //AssertUtil.hasLength(orgCity,"出发城市不能为空");
        //AssertUtil.hasLength(dstCity,"到达城市不能为空");
        //AssertUtil.hasLength(depTime.toString(),"出发日期不能为空");
        return flightMessageMapper.queryFlightMessage(orgCity,dstCity,time);
    }


}
